package com.lhj.crm.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lhj.crm.entity.Department;
import com.lhj.crm.mapper.DepartmentMapper;
import com.lhj.crm.service.IDepartmentService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author FYI
 * @since 2020-03-24
 */
@Service
@Transactional
public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Department> implements IDepartmentService {

    @Autowired
    private DepartmentMapper departmentMapper;
    @Override
    public IPage<Department> selectPageList(Page<Department> deptPage) {
        IPage<Department> departmentIPage = departmentMapper.selectPageList(deptPage);
        return departmentIPage;
    }

    @Override
    public Integer add(Department department) {
        department.setCreateTime(new Date());
        //获取创建时间，可以提高一点性能
        department.setUpdateTime(department.getCreateTime());
        department.setIsDel(0);
        int insert = departmentMapper.insert(department);
        return insert;
    }

    @Override
    public Integer update(Department department) {
        //获取创建时间，可以提高一点性能
        department.setUpdateTime(new Date());
        department.setIsDel(0);
        int updateById = departmentMapper.updateById(department);
        return updateById;
    }
}
